<template>
  <div class="login-container">
    <el-row>
      <el-col :span="6" :push="9">
        <el-form
          ref="loginForm"
          :rules="login.rules"
          :model="login"
          label-width="100px"
          class="login-page demo-ruleForm"
        >
          <el-form-item label="用户名:" prop="userName">
            <el-input v-model="login.userName"></el-input>
          </el-form-item>

          <el-form-item label="用户密码:" prop="passWord">
            <el-input type="password" v-model="login.passWord"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="Login()">登录</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      login: {
        userName: "",
        passWord: "",
        rules: {
          userName: [{ required: true, message: "请输入用户名" }],
          passWord: [{ required: true, message: "请输入密码" }]
        }
      }
    };
  },
  methods: {
    Login() {
    //   console.log("login");
    //一个验证？
      this.$refs["loginForm"].validate(valid => {
        if (valid) {
          this.$myaxios
            .get("AdminUserManager/Login", {
              params: {
                userName: this.login.userName,
                pwd: this.login.passWord
              }
            })
            .then(r => {
              if (r.code == 1 && r.data) {
               
                //   cookesTools,在main里声明的单词对不上，一式两份，这里一份，进行验证。
                // 这里对应着cookesTools里头的setToken里头的第一个值，他是一个值，所以也要是一个值，不然会登录不上
                // this.$cookesTools.setToken(r.data.token);
                this.$cookesTools.setLoginUser(r.data);
                this.$router.push("/i");
              } else {
                this.$message(r.mess);
              }
            });
        }
      });
    }
  }
};
</script>

<style scoped>
.login-container {
  width: 100%;
  height: 100%;
}
.login-page {
  -webkit-border-radius: 5px;
  border-radius: 5px;
  margin: 180px auto;
  width: 350px;
  padding: 35px 35px 15px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
label.el-checkbox.rememberme {
  margin: 0px 0px 15px;
  text-align: left;
}
</style>
